<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
JsWs Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="scriptcontext.js Overview";
	
}
</script>
</head>
<body bgcolor="white" onload="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b>JsWs</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>scriptcontext.js</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		No overview generated for 'scriptcontext.js'<BR/><BR/>
	
</p>

<hr>


    <table border="1" cellpadding="3" cellspacing="0" width="100%">
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
    <td colspan=2><font size="+2">
    
        <b>Class Summary</b>
    
    </font></td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="ScriptContext.html">ScriptContext</a></b></td>
    <td>Provides utilities and context to dynamic webpages
 </td>
    </tr>
    
    </table>
    <hr/> 


<!-- ========== METHOD SUMMARY =========== -->

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"><span class="comment">/* ***** BEGIN LICENSE BLOCK *****
 *   Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 * 
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is JsWs.
 *
 * The Initial Developer of the Original Code is
 * Chris Winberry.
 * Portions created by the Initial Developer are Copyright (C) 2007
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 * 
 * ***** END LICENSE BLOCK ***** */</span>


<span class="comment">/**
 * <span class="attrib">@class</span> Provides utilities and context to dynamic webpages
 * <span class="attrib">@constructor</span>
 * <span class="attrib">@param</span> {JsWsConnectionHandler} server JsWs server object
 * <span class="attrib">@param</span> {VirtualPath|String} sPath Location of the currently executing script
 * <span class="attrib">@exception</span> ExParamError
 */</span>
<span class="reserved">function</span> ScriptContext (server, path) {
	<span class="reserved">if</span> ((typeof path == <span class="literal">"string"</span>) || (path instanceof String))
		path = new VirtualPath(path);
	<span class="reserved">if</span> (!(path instanceof VirtualPath))
		throw(new ExParamError(<span class="literal">"Parameter \"</span>path\<span class="literal">" is of an unexpected type ("</span> + typeof path + <span class="literal">")"</span>, 0, null, arguments));

	<span class="comment">/** <span class="attrib">@private</span> */</span>
	<span class="reserved">this</span>.server = server;

	<span class="comment">/**
	 * Path to the requested webpage
	 * <span class="attrib">@type</span> nsILocalFile
	 */</span>
	<span class="reserved">this</span>.path = path;

	<span class="comment">/**
	 * Path to the folder containing the requested webpage
	 * <span class="attrib">@type</span> nsILocalFile
	 */</span>
	<span class="reserved">this</span>.root = null;
	var fullPath = <span class="reserved">this</span>.mapPath(<span class="reserved">this</span>.path);
	<span class="comment">//if (fullPath.exists()) {</span>
	<span class="reserved">if</span> (fullPath.exists())
		<span class="reserved">if</span> (fullPath.isDirectory())
			<span class="comment">//var tmpPath = this.path.clone();</span>
			<span class="comment">//this.server.tools.appendPath(tmpPath, "index." + JSWS_SCRIPT_FILEEXT);</span>
			<span class="comment">//if (tmpPath.exists() &amp;&amp; tmpPath.isFile()) {</span>
			<span class="comment">//	this.path = tmpPath;</span>
			<span class="comment">//}</span>
			<span class="comment">//this.root = this.path.clone();</span>
			<span class="reserved">this</span>.root = <span class="reserved">this</span>.path;
		<span class="reserved">else</span>
			<span class="reserved">this</span>.root = <span class="reserved">this</span>.path.parent();
	<span class="comment">//}</span>
	<span class="reserved">else</span>
		<span class="reserved">this</span>.root = <span class="reserved">this</span>.path.parent();

	var script = <span class="reserved">this</span>;
	<span class="comment">/** <span class="attrib">@private</span> */</span>
	<span class="reserved">this</span>.VirtualPath = <span class="reserved">function</span> (path) {
		<span class="reserved">if</span> (path.match(/^\/|\\/))
			script.VirtualPath.baseConstructor.call(<span class="reserved">this</span>, path);
		<span class="reserved">else</span> {
			script.VirtualPath.baseConstructor.call(<span class="reserved">this</span>, script.root.path);
			<span class="reserved">this</span>.append(path);
		}
	}
	SubClass(VirtualPath, script.VirtualPath);
}

<span class="comment">/**
 * Runs cleanup on internal objects
 */</span>
ScriptContext.<span class="reserved">prototype</span>.destroy = <span class="reserved">function</span> () {
	<span class="reserved">this</span>.server = null;
	<span class="reserved">this</span>.path = null;
	<span class="reserved">this</span>.root = null;
}

<span class="comment">/**
 * Calculates an absolute path. The passed-in path is treated as relative to server's
 *  document root if the path begins with a "/". It is treated as relative to the
 *  executing script if the path does not begin with a "/".
 * <span class="attrib">@param</span> {String} path Path to resolve to an absolute path
 * <span class="attrib">@returns</span> Full path to in the context of the local filesystem
 * <span class="attrib">@type</span> nsILocalFile
 * <span class="attrib">@exception</span> ExParamError
 */</span>
ScriptContext.<span class="reserved">prototype</span>.mapPath = <span class="reserved">function</span> (path) {
	<span class="reserved">if</span> ((typeof path == <span class="literal">"string"</span>) || (path instanceof String)) {
		<span class="reserved">if</span> (path.match(/^\/|\\/))
			path = new VirtualPath(path);
		<span class="reserved">else</span> {
			var tmp = new VirtualPath(<span class="reserved">this</span>.root);
			tmp.append(path);
			path = tmp;
		}
	}
	<span class="reserved">if</span> (!(path instanceof VirtualPath))
		throw(new ExParamError(<span class="literal">"Parameter \"</span>path\<span class="literal">" is of an unexpected type ("</span> + typeof path + <span class="literal">")"</span>, 0, null, arguments));

	var mappedModule = <span class="reserved">this</span>.server.mapModule(path);
	var finalPath = mappedModule.extensionPath
		+ VirtualPath.sysSeparator
		+ VirtualPath.sysNrml(mappedModule.contentPath)
		+ VirtualPath.sysSeparator
		+ VirtualPath.sysNrml(path.path.substring(mappedModule.virtualPath.length, path.path.length))
		;
	
	var oFile = Cc[<span class="literal">"@mozilla.org/file/local;1"</span>].
		createInstance(Ci.nsILocalFile);
	try {
		oFile.initWithPath(finalPath);
	} catch (e) { JsWs.log(e + <span class="literal">"\n"</span> + finalPath); }

	<span class="reserved">return</span>(oFile);
}

</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b>JsWs</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Thu Nov  8 22:50:16 2007</div>
</body>
</html>
